package com.cstam.service;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.cstam.dao.NewsDao;
import com.cstam.dao.UserDao;
import com.cstam.domain.News;
import com.cstam.domain.User;

public class NewsManagerImpl implements NewsManager{

	@Autowired
	//@Qualifier("userDao")
	private NewsDao newsDao;
	
	@Override
	public boolean createNews(String author, String title, String text,String type) {
		// TODO Auto-generated method stub
		News news = new News();
		news.setAuthor(author);
		news.setTitle(title);
		news.setText(text);
		java.util.Date ucDate = new java.util.Date();
		java.sql.Date scDate = new java.sql.Date(ucDate.getTime());
		news.setTime(scDate);
		news.setType(type);
		
		int ret= newsDao.createNews(news);
		if(ret>0)
			return true;
		else
			return false;
	}

	@Override
	public boolean modifyNews(int newsId,String author,String title,String text,String type) {
		News news = new News();
		news.setNewsid(newsId);
		news.setAuthor(author);
		news.setTitle(title);
		news.setText(text);
		news.setType(type);
		
		int ret= newsDao.modifyNews(news);
		if(ret>0)
			return true;
		else
			return false;
	}

	@Override
	public boolean removeNews(int newsId) {
		int ret=newsDao.removeNews(newsId);
		if(ret>0)
			return true;
		else
			return false;
	}

	//@Override
	//public List<News> getNewsByKey(String keywords) {
		// TODO Auto-generated method stub
		//return newsDao.getNewsByKey(keywords);
	//}

	@Override
	public News getNewsById(int newsId) {
		// TODO Auto-generated method stub
		return newsDao.getNewsById(newsId);
	}

	@Override
	public List<News> getNewsByAuthor(String author) {
		// TODO Auto-generated method stub
		return newsDao.getNewsByAuthor(author);
	}
	
	@Override
	public List<News> getNewsByTitle(String title) {
		// TODO Auto-generated method stub
		return newsDao.getNewsByTitle(title);
	}

	@Override
	public List<News> getNewsByTime(int num) {
		// TODO Auto-generated method stub
		return newsDao.getNewsByTime(num);
	}

	@Override
	public List<News> getNewsByTime(int num_A, int num_B) {
		// TODO Auto-generated method stub
		return newsDao.getNewsByTime(num_A, num_B);
	}

	@Override
	public List<News> getNewsByTime(Date from, Date to) {
		// TODO Auto-generated method stub
		return newsDao.getNewsByTime(from, to);
	}

}
